package main

import (
	. "whoops/leetcode/common"
)

//#link: https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
func main() {

}

//利用双指针，当a走完了换成b的头继续走，b走完了同理，这样两者都会走相同步数，所以会发现相交点
func getIntersectionNode(headA, headB *ListNode) *ListNode {
	if headA == nil || headB == nil {
		return nil
	}
	tempA, tempB := headA, headB
	for tempA != tempB {
		if tempA != nil {
			tempA = tempA.Next
		} else {
			tempA = headB
		}
		if tempB != nil {
			tempB = tempB.Next
		} else {
			tempB = headA
		}
	}
	return tempA
}
